package com.example.spindrift.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
@Slf4j
public class ExceptionHandlerAdvice {
    @ExceptionHandler(Exception.class)
    public ResponseResult handleException(Exception e)
    {
        System.out.println(e);
//        return new ResponseResult(ResponseCode.SERVICE_ERROR.getCode(),ResponseCode.SERVICE_ERROR.getMsg(),null);
        return new ResponseResult(ResponseCode.SERVICE_ERROR.getCode(),e.getMessage(),null);
    }
    @ExceptionHandler(RuntimeException.class)
    public ResponseResult handleRuntimeException(RuntimeException e){
        System.out.println(e);
        return new ResponseResult(ResponseCode.SERVICE_ERROR.getCode(),e.getMessage(),null);
    }
    @ExceptionHandler(BaseException.class)
    public ResponseResult handleBaseException(BaseException e){
        System.out.println(e);
        ResponseCode code = e.getCode();
//        return new ResponseResult(code.getCode(),code.getMsg(),null);
        return new ResponseResult(code.getCode(),e.getMessage(),null);
    }
}
